import scrapy


class QiushiSpider(scrapy.Spider):
    name = 'qiushi'
    # allowed_domains = ['https://www.qiushibaike.com/text']
    start_urls = ['https://www.qiushibaike.com/text/']

    def parse(self, response):
        div_list = response.xpath('//div[@class="col1 old-style-col1"]/div')
        # print(div_list)
        all_dic = []
        for div in div_list:
            # extract_first()
            # author = div.xpath('./div[@class="author clearfix"]//h2/text()')[0].extract()
            author = div.xpath('./div[@class="author clearfix"]//h2/text()').extract_first()
            content = div.xpath('.//div[@class="content"]/span/text()').extract()
            print(author, content)
            dic = {
                "author": author, 'content': content
            }
            all_dic.append(dic)
        return all_dic
